{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD2CAYAAADGbHw0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecVNX9//HXKqIoimJPUFCDvYAKqNhQsSTG2GLHLopG\nlEjQr2JFEAsYuxgb9h5FediIBY1YSIxGBWzBrqiAYKfs7w9/770zd2Z2Z3dn7tw5837+s8udcs/e\nnT187jmf8zl19fX1mJlZ9Vuk0g0wM7PScIduZhYId+hmZoFwh25mFgh36GZmgXCHbmYWCHfoZmaB\ncIduZhYId+hmZoFwh25mFog2SZ6srq6uJuoM1NfX1xX7XF+TXL4m+fm65PI1yeYI3cwsEO7QzcwC\n4Q7dzCwQ7tDNzALhDt3MLBDu0M3MApFo2mKa7L333gDcd999ANTV/ZIVtNdeewHw4IMPVqZhVlEH\nH3wwALfeeisAc+fOBeD4448H4B//+AcAn3/+eQVaZ9Y4R+hmZoGouQj9lFNOAeCkk04CIL6n6uWX\nXw7AZptt1nDs3HPPBWD+/PlJNLHsdthhByCKNgvtK3vllVcCMHDgwGQaliK6Ju3btwfglltuAWDy\n5MkA9OrVqzINS8gWW2wBQN++fYHob6AQ3eH++OOPAGy11VYNj7366qvlaGLZ7bLLLgD07NkTgJNP\nPhmA5ZZbDoju8tN0N+8I3cwsEHWForOynKyCy3QVmR999NEArL322lmPK8LIdz303Pfee6+oc6V9\n6bIipk022QQoHKHLAw88AMBtt93WcOyhhx5q1jnTek06duwIRFFWt27dAFhqqaXyPl93cIMGDWr1\nudO09H/DDTcE4LDDDgOiv5MOHTq06P2++OKLhu/79esHwIQJE4p6baU+KyussAIQfd433XRTAJZc\ncsm8z9fdyKxZs/I+fvrppwMwfvx4AL766qsWt81L/83MakxwY+iKuLbffnsAbrjhBiD6X7ZNm+wf\necaMGUAUoa+44opJNDNRXbt2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WWUaXWgJZ7mYmdUYd+hmZoGouiEX3fpq0nP77bcHoG/f\nvkDuLbFSjDTBV8wkaLFt0LCISpFOnz5dbUjFwog0SeKa6DMB8OKLLwLRpsZFnBMoPKSiiWItLtOw\nm8oxZ76Hhlya2iQjqSEXbScH0ebo2qRBw1QagkzDRHil/n408XvQQQeV5P2U1qziXfvuu2/DY829\nzh5yMTOrMVUXoVcDR+i5kr4m2sxD0Wk8BS3POYEoQtckuoq2aTK6lKmHSUXo1aZSfz+6m3vnnXeA\n3MWIcUoL1SYpmliOb8Kjz5QWOUJ2UkMxHKGbmdUYR+hl4Ag9l69JLkfo+VX6s6KyG9qSMXPxGESp\nnCqhoc3paIMGAAAA0ElEQVTVNbemsiTalL1jx45A6zYVcYRuZlZjHKGXQaUjjDTyNcnlCD0/f1Zy\nOUI3M6sx7tDNzALhDt3MLBDu0M3MAuEO3cwsEIlmuZiZWfk4QjczC4Q7dDOzQLhDNzMLhDt0M7NA\nuEM3MwuEO3Qzs0C4QzczC4Q7dDOzQLhDNzMLhDt0M7NAuEM3MwuEO3Qzs0C4QzczC4Q7dDOzQLhD\nNzMLhDt0M7NAuEM3MwuEO3Qzs0C4QzczC4Q7dDOzQLhDNzMLhDt0M7NAuEM3MwvE/wPyFjJ7D14k\nIQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fe21849f5d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from sklearn.datasets import fetch_mldata\n",
    "import matplotlib.cm as cm\n",
    "\n",
    "mnist = fetch_mldata('MNIST original', data_home='data/mnist')\n",
    "\n",
    "counter = 1\n",
    "for i in range(1, 4):\n",
    "    for j in range(1, 6):\n",
    "        plt.subplot(3, 5, counter)\n",
    "        plt.imshow(mnist.data[(i - 1) * 8000 + j].reshape((28, 28)), cmap=cm.Greys_r)\n",
    "        plt.axis('off')\n",
    "        counter += 1\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fitting 3 folds for each of 30 candidates, totalling 90 fits\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=2)]: Done  46 tasks      | elapsed: 54.0min\n",
      "[Parallel(n_jobs=2)]: Done  90 out of  90 | elapsed: 101.9min finished\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best score: 0.965\n",
      "Best parameters set:\n",
      "\tclf__C: 3\n",
      "\tclf__gamma: 0.01\n",
      "             precision    recall  f1-score   support\n",
      "\n",
      "        0.0       0.98      0.98      0.98      1770\n",
      "        1.0       0.99      0.98      0.98      1987\n",
      "        2.0       0.95      0.97      0.96      1738\n",
      "        3.0       0.96      0.96      0.96      1808\n",
      "        4.0       0.97      0.98      0.97      1703\n",
      "        5.0       0.96      0.96      0.96      1549\n",
      "        6.0       0.98      0.98      0.98      1677\n",
      "        7.0       0.98      0.96      0.97      1827\n",
      "        8.0       0.96      0.95      0.96      1701\n",
      "        9.0       0.96      0.96      0.96      1740\n",
      "\n",
      "avg / total       0.97      0.97      0.97     17500\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.preprocessing import scale\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.grid_search import GridSearchCV\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    X, y = mnist.data, mnist.target\n",
    "    X = X/255.0*2 - 1\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=11)\n",
    "    \n",
    "    pipeline = Pipeline([\n",
    "        ('clf', SVC(kernel='rbf', gamma=0.01, C=100))\n",
    "    ])\n",
    "    \n",
    "    parameters = {\n",
    "        'clf__gamma': (0.01, 0.03, 0.1, 0.3, 1),\n",
    "        'clf__C': (0.1, 0.3, 1, 3, 10, 30),\n",
    "    }\n",
    "\n",
    "    grid_search = GridSearchCV(pipeline, parameters, n_jobs=2, verbose=1, scoring='accuracy')\n",
    "    grid_search.fit(X_train[:10000], y_train[:10000])\n",
    "    print('Best score: %0.3f' % grid_search.best_score_)\n",
    "    print('Best parameters set:')\n",
    "    best_parameters = grid_search.best_estimator_.get_params()\n",
    "    for param_name in sorted(parameters.keys()):\n",
    "        print('\\t%s: %r' % (param_name, best_parameters[param_name]))\n",
    "    \n",
    "    predictions = grid_search.predict(X_test)\n",
    "    print(classification_report(y_test, predictions))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
